<template>
  <div class="mainDiv">
      <el-row :gutter="20" class="rowHead">
          <el-col :span="16" id="el-col-16">
              <el-tag type="success">筛选：</el-tag>
              <el-date-picker v-model="searchinfo.times" type="daterange" align="right" placeholder="选择日期范围" :picker-options="pickerOptions" @change="getList">
              </el-date-picker>
              <el-select v-model="searchinfo.type" @change="getList">
                  <el-option :key="0" label="请选择预约类型" :value="0"></el-option>
                  <el-option :key="1" label="类型1" :value="1"></el-option>
                  <el-option :key="2" label="类型2" :value="2"></el-option>
                  <el-option :key="3" label="类型3" :value="3"></el-option>
              </el-select>
              <el-select v-model="searchinfo.status" @change="getList">
                  <el-option label="请选择状态" :value="0"></el-option>
                  <el-option label="已预约" :value="1"></el-option>
                  <el-option label="已完成" :value="2"></el-option>
                  <el-option label="已取消" :value="3"></el-option>
              </el-select>
              <el-checkbox v-model="searchinfo.ischeck" label="预约在当天" @change="getList" border></el-checkbox>     
          </el-col>
          <el-col :span="8" class="flex_center">
            <el-input placeholder="搜索客户" v-model="searchinfo.search" @keyup.enter.native="getList">
                <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
            </el-input>
            <el-button type="primary" @click="getList" style="margin-left: 5px" icon="h-shuaxin1">刷新列表</el-button>
          </el-col>
      </el-row>
      <el-table :data="reservationlist" :stripe="true" height="100%">
        <el-table-column prop="id" label="#" width="80"></el-table-column>
        <el-table-column prop="gname" label="客户">
            <template slot-scope="scope">
                <span @click="openGuestPage(scope.row.guestid)" style="cursor:pointer;color:#f50">{{scope.row.gname}}</span>
            </template>
        </el-table-column>
        <el-table-column prop="uname" label="预约员工" show-overflow-tooltip></el-table-column>
        <el-table-column prop="datetime" label="预约时间" :show-overflow-tooltip="true" width="180"></el-table-column>
        <el-table-column prop="type" label="预约类型">
          <template slot-scope="scope">
            <Tags :typeValue="scope.row.type" typeName="yuyueType"></Tags>
          </template>
        </el-table-column>
        <el-table-column prop="num" label="客户人数"></el-table-column>
        <el-table-column prop="sname" label="预约项目"></el-table-column>        
         <el-table-column prop="arrivetime" label="到店时间" :show-overflow-tooltip="true" width="180">
            <template slot-scope="scope">
                {{scope.row.arrivetime|hourTime}}
            </template>
        </el-table-column>
        <el-table-column prop="remarks" label="客户备注"></el-table-column>
        <el-table-column prop="status" label="预约状态">
              <template slot-scope="scope">
                  <Tags :typeValue="scope.row.status" typeName="yuyueStatus"></Tags>
              </template>
          </el-table-column>
        <el-table-column label="操作" width="180">
            <template slot-scope="scope">
              <el-button-group>
                  <el-tooltip content="取消" placement="top">
                      <el-button v-if="scope.row.status == 1" type="warning" icon="el-icon-h-close" size="mini" @click="cancel(scope.row.id)"></el-button>
                      <el-button v-else type="info" icon="el-icon-h-close" size="mini" disabled></el-button>
                  </el-tooltip>
                  <el-tooltip content="到店" placement="top">
                      <el-button v-if="scope.row.status == 1" icon="el-icon-h-biaozhu" type="danger" size="mini" @click="toshop(scope.row.id)"></el-button>
                      <el-button v-else icon="el-icon-h-biaozhu" type="info" size="mini" disabled></el-button>
                  </el-tooltip>
              </el-button-group>
            </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 14px;">
          <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="searchinfo.pages" :page-sizes="[15, 30, 50, 100]" :page-size="searchinfo.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
      </div>
  </div>
</template>
<script>
import C from '@/common/common.js'
import Guest from '@/service/shop/guest.js'
import Tags from '@/components/orderTags.vue'

export default {
  data () {
    return {
      reservationlist: [],
      total: 0,
      searchinfo: {
        type: 0,
        status: 0,
        search: '',
        ischeck: false,
        times: [new Date().setDate(new Date().getDate() - 3), new Date()],
        pages: 1,
        limits: 15
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  components: { Tags },
  mounted: function () {
    this.getList()
  },
  methods: {
    getList: async function () {
      let that = this
      let data = await C.ajax('/shop/guest/guestAppoint', that.searchinfo, 'post')
      data.data.forEach(element => {
        element.datetime = element.date + ' ' + element.time
      })
      that.reservationlist = data.data
      that.total = data.count
    },
    cancel: async function (id) {
      let that = this
      C.confirm('确定取消该笔预约单?', async () => {
        let res = await C.ajax('/shop/guest/cancel', { id: id }, 'post')
        C.success(res.data)
        that.getList()
      })
    },
    toshop: async function (id) {
      let that = this
      C.confirm('该客户确定到店?', async () => {
        let res = await C.ajax('/shop/guest/guestToshop', { id: id }, 'post')
        C.success(res.data)
        that.getList()
      })
    },
    sizeChange: function (val) {
      this.searchinfo.limits = val
      this.getList()
    },
    currentChange: function (val) {
      this.searchinfo.pages = val
      this.getList()
    },
    openGuestPage (id) {
      Guest.openGuestPage(id)
    }
  }
}
</script>
<style>
</style>